import {getConfig, setConfig} from '@/mapper/config-store';

export async function getMesEventConfig(eventName) {
    const key = `mesEventConfig.${eventName}`
    let eventConfig = await getConfig(key)
    if (!eventConfig) {
        return defaultData[eventName]
    }
    return eventConfig
}

export async function saveMesEventConfig(eventName, data) {
    const key = `mesEventConfig.${eventName}`
    //保存的时候校验字段，从defaultData中读取，如果有多余的，就去掉
    let keys = Object.keys(defaultData[eventName])
    let newData = {}
    keys.forEach(key => {
        newData[key] = data[key]
    })
    await setConfig(key, newData)
    return 'ok'
}


const defaultData = {
    "SN_CheckIn": {
        "enabled": false,
        "url": 'http://10.50.4.200/Q_HttpService/Default.aspx',
        "EventID": "SN_CheckIn",
        "Line": "Y-FA-01",
        "StationID": "WHEELASSEMBLYTEST",
        "MachineID": "Q68-E1A4-WAT-01",
        "OPID": "YUYUE",
        "Token": "1",
        "FixSN": "1",
        "SN": "F1#20250207#0860",
        "CarrierID": "",
        "SendTime": "2025/02/08 08:32:05"
    },
    "SN_CheckOut": {
        "enabled": false,
        "url": 'http://10.50.4.200/Q_HttpService/Default.aspx',
        "EventID": "SN_CheckOut",
        "Line": "J1A4",
        "StationID": "LOCK STATOR SCREW",
        "MachineID": "LSS01",
        "OPID": "123",
        "Token": "NA",
        "FixSN": "NA",
        "SN": "LUX5117000J6820X2Y",
        "Result": "PASS",
        "DC_Info": [
            {
                "Item": "TOR1",
                "Value": "1.652"
            },
            {
                "Item": "TRUNS1",
                "Value": "3854"
            },
            {
                "Item": "HEIGHT1",
                "Value": "156"
            }
        ],
        "CompList": [],
        "SendTime": "2025/03/17 11:04:21"
    },
    "Status": {
        "enabled": false,
        "url": 'http://10.50.4.200/Q_HttpService/Default.aspx',
        "EventID": "Status",
        "Line": "V66_Cover_01",
        "StationID": "Cover",
        "MachineID": "",
        "Token": "",
        "FixSN": "12345",
        "OPID": "12345",
        "STATUS": "X_XXX",
        "SendTime": ""
    },
    "Alarm": {
        "enabled": false,
        "url": 'http://10.50.4.200/Q_HttpService/Default.aspx',
        "EventID": "Alarm",
        "Line": "V66_Cover_01",
        "StationID": "Cover",
        "MachineID": "",
        "OPID": "12345",
        "AlarmID": "XXXXXX",
        "SendTime": "",
        "ResetTime": ""
    }
}
